<?php
require_once '../../../include/cp_header.php';

require_once XOOPS_ROOT_PATH . '/modules/'.$xoopsModule->getVar('dirname').'/libclasses/lib.std.php';
require_once XOOPS_ROOT_PATH . '/modules/'.$xoopsModule->getVar('dirname').'/libclasses/lib.shop.php';


$action =$_GET['action'];

switch ($action) {
    case 'loadcat':
        $cat= loadCat($_GET['catid']);
        $str=json_encode($cat);
        echo $str;
        break;
     case 'savecat':
        $cat= insertCategory($_GET['catid']);
        $str=json_encode($cat);
        echo $str;
        break;
}





/**
* Add a new category under the parent $id.
* All the fields that we want are going to be in the variable $frm.
*/
function insertCategory($id, $frm)
{
	global $xoopsDB;


	(isset($frm['c_show_image'])) ? $frm['c_show_image']=1 : $frm['c_show_image']='';

	//Sanitize text
	$myts = myTextSanitizer::getInstance();
	$frm['c_desc'] = $myts->addslashes($frm['c_desc']);
	$frm['c_name'] = $myts->addslashes($frm['c_name']);


$query = "Insert into ".$xoopsDB->prefix("kshop_categories")."
					(c_parent_id, c_name, c_description, c_order, c_image, c_show_image)
	VALUES ('$frm[parent]', '$frm[c_name]', '$frm[c_desc]', '$frm[c_order]', '$frm[c_image]', '$frm[c_show_image]')";

	$res=$xoopsDB->query($query);
	if(!$res) {
		echo "error: $query";
	}

	//-- get the product id that was just created.
	$product_id = mysql_insert_id();

redirect_header('categories.php', 1, KS_CREATCATSUCESS);
die();
}


?>
